import { login, getUserDetail } from '../../api/services/user'
export default ({
    namespaced: true,
    state: {
        loginStu: false,
        user: {
            userId: 0,
            nickname: '',
            avatarUrl: '',
            gender: '',
            vipType: '',

        }
    },
    mutations: {
        changLogin(state) {
            state.loginStu = true;
        },
        //获取当前登录状态
        getLoginStu(state) {
            state.loginstu = JSON.parse(localStorage.getItem('loginStatu'));
            state.user.id = JSON.parse(localStorage.getItem('userId'));
        },
        changeUserInfo(state, val) {
            state.user = { ...val };
        }
    },
    actions: {
        //登录账号
        async userLogin(context, val) {
            const data = await login(val.myPhone, val.myPassword);
            if (data.code === 200) {
                context.commit('changLogin');
                return data;
            }
        },
        async getUserDetail(context, val) {
            let id = JSON.parse(localStorage.getItem('userId'));
            const data = await getUserDetail(id);
            console.log('用户详情', data);
            context.commit('changeUserInfo', data.profile);
            context.commit('changLogin');
        }
    },

})
